reftests: Add a --output option to the test runner
authorBenjamin Otte <otte@redhat.com>
Tue, 3 May 2011 12:03:25 +0000 (14:03 +0200)
committerBenjamin Otte <otte@redhat.com>
Tue, 3 May 2011 13:40:49 +0000 (15:40 +0200)
This argument specifies where to dump images instead of /tmp. It's not
hooked up to the test runner, so that one will continue to dump into
/tmp.

tests/reftests/gtk-reftest.c

index 4670b3fde9cc4e93cd9d5faf60d6e585ddc07a29..012c0b4122b604093586eebdc567c93caf6d55ab 100644 (file)
@@ -34,6 +34,35 @@ typedef enum {
 /* This is exactly the style information you've been looking for */
 #define GTK_STYLE_PROVIDER_PRIORITY_FORCE G_MAXUINT
 
+static char *arg_output_dir = NULL;
+
+static const GOptionEntry test_args[] = {
+  { "output",         'o', 0, G_OPTION_ARG_FILENAME, &arg_output_dir,
+    "Directory to save image files to", "DIR" },
+  { NULL }
+};
+
+static gboolean
+parse_command_line (int *argc, char ***argv)
+{
+  GError *error = NULL;
+  GOptionContext *context;
+
+  context = g_option_context_new ("- run GTK reftests");
+  g_option_context_add_main_entries (context, test_args, NULL);
+  g_option_context_set_ignore_unknown_options (context, TRUE);
+
+  if (!g_option_context_parse (context, argc, argv, &error))
+    {
+      g_print ("option parsing failed: %s\n", error->message);
+      return FALSE;
+    }
+
+  gtk_test_init (argc, argv);
+
+  return TRUE;
+}
+
 static const char *
 get_output_dir (void)
 {
@@ -43,7 +72,16 @@ get_output_dir (void)
   if (output_dir)
     return output_dir;
 
-  output_dir = g_get_tmp_dir ();
+  if (arg_output_dir)
+    {
+      GFile *file = g_file_new_for_commandline_arg (arg_output_dir);
+      output_dir = g_file_get_path (file);
+      g_object_unref (file);
+    }
+  else
+    {
+      output_dir = g_get_tmp_dir ();
+    }
 
   if (!g_file_test (output_dir, G_FILE_TEST_EXISTS))
     {
@@ -499,7 +537,8 @@ add_tests_for_files_in_directory (GFile *dir)
 int
 main (int argc, char **argv)
 {
-  gtk_test_init (&argc, &argv);
+  if (!parse_command_line (&argc, &argv))
+    return 1;
 
   if (argc < 2)
     {